INPUT_FILE=$1
awk -F"," 'BEGIN {
    OFS = ",";
    buy[0] = buy[1] = -1;
    sell[0] = sell[1] = -1;
    time[0] = time[1] = "";
} {
    if ($3 == "IF1503")
        f = 0;
    else if ($3 == "IF1504")
        f = 1;
    else 
        f = -1;
    bsd = sbd = "";
    if (f != -1) {
        buy[f] = $24;
        sell[f] = $26;
        time[f] = $22":"$23;
        if (time[1-f] == time[f]) {
            bsd = buy[0] - sell[1];
            sbd = sell[0] - buy[1];
        }
    }
    year = substr($2, 1, 4);
    month = substr($2, 5, 2);
    day = substr($2, 7, 2);
    hour = substr($22, 1, 2);
    minute = substr($22, 4, 2);
    sec = substr($22, 7, 2);
    s1 = mktime(year" "month" "day" "hour" "minute" "sec);
    if (hour > 15) {
        s1 -= 86400;
    }
    date = strftime("%Y%m%d", s1);
    
    year2 = substr($1, 1, 4);
    month2 = substr($1, 5, 2);
    day2 = substr($1, 7, 2);
    hour2 = substr($1, 10, 2);
    minute2 = substr($1, 13, 2);
    sec2 = substr($1, 16, 2);
    s2 = mktime(year2" "month2" "day2" "hour2" "minute2" "sec2);
    
    #print year,month,day,hour,minute,sec,s1,year2,month2,day2,hour2,minute2,sec2,s2;    
    if (s2 - s1 <= 60 && ($3 == "IF1503" || $3 == "IF1504")) {
        print $1,date"#"$22":"$23","$3,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$18,$19,$24,$25,$26,$27,bsd,sbd;
    }
}' ${INPUT_FILE}
